package com.feige.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.feige.constant.Constants;
import com.feige.dao.ExerciseTitleMapper;
import com.feige.pojo.ExerciseTitle;
import com.feige.pojo.vo.ExerciseTitleVo;
import com.feige.result.AjaxResult;
import com.feige.service.ExerciseTitleService;
import com.feige.utils.jwt.JwtUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 习题标题 服务实现类
 * </p>
 *
 * @author feige
 * @since 2021-04-01
 */
@Service
public class ExerciseTitleServiceImpl extends ServiceImpl<ExerciseTitleMapper, ExerciseTitle> implements ExerciseTitleService {

    @Resource
    private JwtUtils jwtUtils;

    @Override
    public AjaxResult getStuExerciseTitleByCourseId(Integer pageNum, String id, String token) {
        String userId = jwtUtils.getUserIdByToken(token);
        Page<ExerciseTitleVo> page = new Page<>(pageNum, Constants.PAGE_SIZE * 2);
        this.baseMapper.getExerciseTitleVo(page,id,userId);
        AjaxResult success = AjaxResult.success(page.getRecords());
        success.put("total",page.getTotal());
        return success;
    }
}
